package org.example.curriculum_design_6_16.mapper;

import org.apache.ibatis.annotations.*;
import org.example.curriculum_design_6_16.entity.pojo.CompetitionParticipation;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
* @author 郑凯
* @description 针对表【competition_participation】的数据库操作Mapper
* @createDate 2025-06-22 21:30:17
* @Entity org.example.curriculum_design_6_16.entity.pojo.CompetitionParticipation
*/
@Mapper
public interface CompetitionParticipationMapper extends BaseMapper<CompetitionParticipation> {
    @Insert("INSERT INTO competition_participation(student_id, competition_id, participation_date, award_level, " +
            "is_team_leader, team_size, score, proof_url, status, review_comment, academic_year) " +
            "VALUES(#{studentId}, #{competitionId}, #{participationDate}, #{awardLevel}, " +
            "#{isTeamLeader}, #{teamSize}, #{score}, #{proofUrl}, #{status}, #{reviewComment}, #{academicYear})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(CompetitionParticipation participation);

    @Update("UPDATE competition_participation SET student_id=#{studentId}, competition_id=#{competitionId}, " +
            "participation_date=#{participationDate}, award_level=#{awardLevel}, is_team_leader=#{isTeamLeader}, " +
            "team_size=#{teamSize}, score=#{score}, proof_url=#{proofUrl}, status=#{status}, " +
            "review_comment=#{reviewComment}, academic_year=#{academicYear} " +
            "WHERE id=#{id}")
    int update(CompetitionParticipation participation);

    @Delete("DELETE FROM competition_participation WHERE id=#{id}")
    int delete(Integer id);

    @Select("SELECT * FROM competition_participation WHERE id=#{id}")
    CompetitionParticipation selectById(Integer id);

    @Select("SELECT * FROM competition_participation")
    List<CompetitionParticipation> selectAll();

    List<CompetitionParticipation> selectByStudentId(String studentId);

    List<CompetitionParticipation> selectByStudentIdAndYear(@Param("studentId") String studentId,
                                                            @Param("academicYear") String academicYear);

    @Select("SELECT * FROM competition_participation WHERE competition_id=#{competitionId}")
    List<CompetitionParticipation> selectByCompetitionId(Integer competitionId);

    @Update("UPDATE competition_participation SET status=#{status}, review_comment=#{reviewComment} " +
            "WHERE id=#{id}")
    int updateStatus(@Param("id") Integer id, @Param("status") String status,
                     @Param("reviewComment") String reviewComment);

    @Select("SELECT cp.* FROM competition_participation cp " +
            "WHERE cp.student_id=#{studentId} AND cp.competition_id=#{competitionId}")
    List<CompetitionParticipation> selectByStudentIdAndCompetitionId(
            @Param("studentId") String studentId,
            @Param("competitionId") Integer competitionId);
}




